/**************************************************************************
** Qt Creator license header template
**   Special keywords: Programmer 2012/3/21 2012
**   Environment variables: 
**   To protect a percent sign, use '%'.
**************************************************************************/

#ifndef MESHSIMPLIFICATIONQUADRIC_H
#define MESHSIMPLIFICATIONQUADRIC_H

#include <vcg/complex/algorithms/local_optimization/tri_edge_collapse_quadric.h>
#include <vcg/complex/algorithms/update/position.h>
#include <vcg/complex/algorithms/update/bounding.h>
#include <vcg/complex/algorithms/update/selection.h>
#include <vcg/complex/algorithms/local_optimization.h>
#include <vcg/complex/algorithms/local_optimization/tri_edge_collapse_quadric.h>
#include <vcg/container/simple_temporary_data.h>

#include "glarea.h"

#include "meshdefs.h"

typedef void (GLArea::*CallBack)();
typedef vcg::SimpleTempData<MyTriMesh::VertContainer, vcg::math::Quadric<double> > QuadricTemp;

class Helper{
public:
    Helper(){}

    static void Init(){}
    static vcg::math::Quadric<double> &Qd(MyVertex &v){return TD()[v];}
    static vcg::math::Quadric<double> &Qd(MyVertex *v){return TD()[v];}
    static MyTriMesh::ScalarType W(MyVertex*){return 1.0;}
    static MyTriMesh::ScalarType W(MyVertex&){return 1.0;}
    static void Merge(MyVertex&,MyVertex const &){}
    static QuadricTemp* &TDp(){static QuadricTemp* td; return td;}
    static QuadricTemp &TD(){return *TDp();}
};

typedef vcg::tri::BasicVertexPair<MyVertex> VertexPair;

class MeshSimplificationQuadric : public vcg::tri::TriEdgeCollapseQuadric<MyTriMesh,VertexPair,MeshSimplificationQuadric,Helper>
{
public:
    typedef  vcg::tri::TriEdgeCollapseQuadric<MyTriMesh,VertexPair,MeshSimplificationQuadric,Helper> TECQ;
    MeshSimplificationQuadric(const VertexPair& p, int i, vcg::BaseParameterClass* pp): TECQ(p,i,pp){}

    //void getParams(vcg::tr)
};
void QuadricSimplification(MyTriMesh& m, int targetFaceNum, bool selected, vcg::tri::TriEdgeCollapseQuadricParameter& pp,GLArea* gl);


#endif // MESHSIMPLIFICATIONQUADRIC_H
